package com.cy;

import java.sql.*;

/**
 * @Author : 残影
 * @Date: 2020-09-12 11:21
 */
public class Demo {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //1.注册驱动
        DriverManager.registerDriver(new com.mysql.jdbc.Driver());
        //Class.forName("com.mysql.jdbc.Driver");
        //2.获取连接
        Connection connection = DriverManager.getConnection("jdbc:mysql://101.200.142.27:33306/framework-spring01", "root", "root");
        //3.获取预处理 sql 语句对象
        PreparedStatement preparedStatement = connection.prepareStatement("select * from account");
        //4.获取结果集
        ResultSet resultSet = preparedStatement.executeQuery();
        //5.遍历结果集
        while (resultSet.next()){
            System.out.println(resultSet.getString("name"));
        }
        //6.释放资源
        resultSet.close();
        preparedStatement.close();
        connection.close();

    }
}
